home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / C Internet Config / IC Application Source ƒ / 68k Internet Config ƒ / C Source ƒ / IC Movable Modal.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-02  |  4.9 KB  |  205 lines  |  [TEXT/SPM ]

  1. /*
  2.     IC Movable Modal.c
  3.     
  4.     This code implements a MovableModalDialog routine similar to the
  5.     Toolbox routine ModalDialog, to be used for movable modal dialogs.
  6.     
  7.     Based on code by Merzwaren (piovanel@dsi.unimi.it)
  8.     
  9. */
  10.  
  11. #include <GestaltEqu.h>
  12. #include <LowMem.h>
  13. #include <Traps.h>
  14. #include <Packages.h>
  15. #include <Dialogs.h>
  16. #include <Balloons.h>
  17.  
  18. #include "IC Types.h"
  19. #include "IC Dialogs.h"
  20. #include "IC Globals.h"
  21. #include "IC Misc Subs.h"
  22. #include "IC Movable Modal.h"
  23.  
  24. #include "Call68kGlue.h"
  25.  
  26. void DisableMenuBar(Ptr* saved_state,short hmnuID){
  27.     MenuListHandle menuList;
  28.     short i,nMenus;
  29.     MenuHandle theMenu;
  30.     short menuID;
  31.     DialogPtr theDialog;
  32.     Boolean hasBalloons=Has_HelpMgr,needEditMenu;
  33.     MenuBarStatePtr state;
  34.     
  35.     theDialog=FrontWindow();
  36.     needEditMenu=((theDialog!=(DialogPtr)0)&&(SelectedTextItem(theDialog)>0));
  37.     
  38.     menuList=(MenuListHandle)LMGetMenuList();
  39.     nMenus=(*menuList)->offsetToLastMenu/sizeof(MenuEntry);
  40.     
  41.     *saved_state=NewPtr(sizeof(MenuBarState));
  42.     state=(MenuBarStatePtr)*saved_state;
  43.     
  44.     state->mbsBarEnable=0;
  45.     
  46.     for (i=0;i<nMenus;i++){
  47.         theMenu=(*menuList)->theMenus[i].hMenu;
  48.         menuID=(*theMenu)->menuID;
  49.         
  50.         if (menuID>kSystemMenuThreshold){ // do nothing if this is a system menu
  51.             if (menuID==M_Edit){
  52.                 state->mbsEditEnable=(*theMenu)->enableFlags;
  53.                 if (needEditMenu)
  54.                     (*theMenu)->enableFlags=1+(1<<EM_Cut)+(1<<EM_Copy)+(1<<EM_Paste);
  55.                 else
  56.                     DisableItem(theMenu,0);
  57.             } else { // if this menu is enabled, disable it and set the corresponding bit
  58.                 if ((*theMenu)->enableFlags&(1<<0)){
  59.                     state->mbsBarEnable |= (1<<i);
  60.                     DisableItem(theMenu,0);
  61.                 }
  62.                 
  63.                 if (hasBalloons){ // remap the help strings for this menu
  64.                     HMSetMenuResID(menuID,hmnuID);
  65.                 }
  66.             }
  67.         }
  68.     }
  69.     
  70.     HiliteMenu(0);
  71.     DrawMenuBar();
  72. }
  73.  
  74. void ReEnableMenuBar(Ptr* saved_state){
  75.     MenuListHandle menuList;
  76.     short i,nMenus;
  77.     MenuHandle theMenu;
  78.     short menuID;
  79.     Boolean hasBalloons=Has_HelpMgr;
  80.     OSErr err;
  81.     MenuBarStatePtr state=(MenuBarStatePtr)*saved_state;
  82.     
  83.     menuList=(MenuListHandle)LMGetMenuList();
  84.     nMenus=(*menuList)->offsetToLastMenu/sizeof(MenuEntry);
  85.     
  86.     for (i=0;i<nMenus;i++){
  87.         theMenu=(*menuList)->theMenus[i].hMenu;
  88.         menuID=(*theMenu)->menuID;
  89.         
  90.         if (menuID>kSystemMenuThreshold){
  91.             if (menuID==M_Edit)
  92.                 (*theMenu)->enableFlags=state->mbsEditEnable;
  93.             else if (state->mbsBarEnable&(1<<i))
  94.                 EnableItem(theMenu,0);
  95.             
  96.             if (hasBalloons)
  97.                 HMSetMenuResID(menuID,-1);
  98.         }
  99.     }
  100.     
  101.     DisposePtr(*saved_state);
  102.     *saved_state=(Ptr)0;
  103.     
  104.     DrawMenuBar();
  105. }
  106.  
  107. pascal void CallBeeper(short soundNo,BeeperUPP beeperProc){
  108.     
  109.     CallBeeperProc(beeperProc,soundNo);
  110. }
  111.  
  112. Boolean DoMenuChoice(DialogPtr theDialog,EventRecord* er,short* itemHit,long menuChoice){
  113.     short menuID,menuItem;
  114.     short currentEditField,itemType;
  115.     Boolean res=false;
  116.     
  117.     menuID=HiWord(menuChoice);
  118.     menuItem=LoWord(menuChoice);
  119.     
  120.     if (menuID==M_Edit){
  121.         currentEditField=SelectedTextItem(theDialog);
  122.         GetDItemKind(theDialog,currentEditField,&itemType);
  123.         
  124.         if ((itemType&itemDisable)==0){
  125.             // if the current edit field is an enabled item, exit from MovableModalDialogLoop
  126.             *itemHit=currentEditField;
  127.             res=true;
  128.             
  129.             if (menuItem==EM_Cut){
  130.                 DialogCut(theDialog);
  131.                 ZeroScrap();
  132.                 TEToScrap();
  133.             } else if (menuItem==EM_Copy){
  134.                 DialogCopy(theDialog);
  135.                 ZeroScrap();
  136.                 TEToScrap();
  137.             } else if (menuItem==EM_Paste){
  138.                 TEFromScrap();
  139.                 DialogPaste(theDialog);
  140.             }
  141.         }
  142.     }
  143.     HiliteMenu(0);
  144.     
  145.     return res;
  146. }
  147.  
  148. Boolean HandleMouseDown(DialogPtr theDialog,EventRecord* theEvent,short* itemHit){
  149.     short partCode;
  150.     WindowPtr wind;
  151.     BeeperUPP beeper;
  152.     Rect dragRect;
  153.     Boolean res=false;
  154.     
  155.     partCode=FindWindow(theEvent->where,&wind);
  156.     
  157.     if (partCode==inMenuBar)
  158.         res=DoMenuChoice(theDialog,theEvent,itemHit,MenuSelect(theEvent->where));
  159.     else if (!PtInRgn(theEvent->where,((WindowPeek)theDialog)->strucRgn)){
  160.         beeper=(BeeperUPP)LMGetDABeeper();
  161.         if (beeper!=(BeeperUPP)0)
  162.             CallBeeperProc(beeper,1);
  163.     } else if ((partCode==inDrag)&&(theDialog==wind)){ // now we have to handle the only thing dialog select doesn't do for us: dragging
  164.         RgnHandle rgn=GetGrayRgn();
  165.         
  166.         dragRect=(*rgn)->rgnBBox;
  167.         DragWindow(wind,theEvent->where,&dragRect);
  168.         theEvent->what=nullEvent;
  169.     }
  170.     
  171.     return res;
  172. }
  173.  
  174. void MovableModalDialog(ModalFilterUPP filterProc,short* itemHit){
  175.     DialogPtr theDialog,junk;
  176.     EventRecord theEvent;
  177.     Boolean gotEvent;
  178.     
  179.     *itemHit=0;
  180.     theDialog=(DialogPtr)FrontWindow();
  181.     if (theDialog!=(DialogPtr)0){
  182.         SetPort(theDialog);
  183.         do {
  184.             gotEvent=WaitNextEvent(kMovableModalEventMask,&theEvent,0,(RgnHandle)0);
  185.             SetPort(theDialog);
  186.             
  187.             if ((filterProc!=(ModalFilterUPP)0)&&CallModalFilterProc(filterProc,theDialog,&theEvent,itemHit))
  188.                 return;
  189.             
  190.             if ((theEvent.what==mouseDown)&&HandleMouseDown(theDialog,&theEvent,itemHit))
  191.                 return;
  192.             
  193.             if ((theEvent.what==keyDown)&&((theEvent.modifiers&cmdKey)!=0)&&
  194.                     DoMenuChoice(theDialog,&theEvent,itemHit,MenuKey(theEvent.message&charCodeMask)))
  195.                 return;
  196.             
  197.             if ((IsDialogEvent(&theEvent))&&(DialogSelect(&theEvent,&junk,itemHit)))
  198.                 return;
  199.         } while (1);
  200.     }
  201. }
  202.  
  203.  
  204.  
  205.